package com.mutual.reins.danger.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mutual.reins.danger.entity.PrptDangerCoins;
import com.mutual.reins.danger.mapper.PrptDangerCoinsMapper;
import com.mutual.reins.danger.service.IPrptDangerCoinsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author CodeGenerate
 * @since 2021-03-31
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class PrptDangerCoinsServiceImpl extends ServiceImpl<PrptDangerCoinsMapper, PrptDangerCoins> implements IPrptDangerCoinsService {

    /**
     * 获取该对象Map（key：投保单号—危险单位号 value：List<PrptDangerCoins>）
     *
     * @param queryWrapper 查询条件
     * @return 获取该对象Map
     */
    @Override
    public Map<String, List<PrptDangerCoins>> selectPrptDangerCoinsMap(QueryWrapper queryWrapper) {
        List<PrptDangerCoins> prptDangerCoinsList = this.list(queryWrapper);
        Map<String,List<PrptDangerCoins>> prptDangerCoinsMap = new HashMap<>(16);
        if(ObjectUtil.isNotNull(prptDangerCoinsList) && !prptDangerCoinsList.isEmpty()){
            for(PrptDangerCoins prptDangerCoins:prptDangerCoinsList){
                if(prptDangerCoinsMap.containsKey(prptDangerCoins.getProposalNo()+"-"+prptDangerCoins.getDangerNo())){
                    List<PrptDangerCoins> prptDangerCoinsMapList = prptDangerCoinsMap.get(prptDangerCoins.getProposalNo()+"-"+prptDangerCoins.getDangerNo());
                    prptDangerCoinsMapList.add(prptDangerCoins);
                }else{
                    List<PrptDangerCoins> prptDangerCoinsMapList = new ArrayList<>();
                    prptDangerCoinsMapList.add(prptDangerCoins);
                    prptDangerCoinsMap.put(prptDangerCoins.getProposalNo()+"-"+prptDangerCoins.getDangerNo(),prptDangerCoinsMapList);
                }
            }
        }
        return prptDangerCoinsMap;
    }
}
